import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout, QFileDialog


class FileUploader(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()
    def initUI(self):
        self.button = QPushButton('上传文件', self)
        self.button.clicked.connect(self.uploadFile)
        layout = QVBoxLayout()
        layout.addWidget(self.button)
        self.setLayout(layout)

    def uploadFile(self):
        options = QFileDialog.Options()
        fileName, _ = QFileDialog.getOpenFileName(self, "选择文件", "", "所有文件 (*);;Python 文件 (*.py)",
                                                  options=options)

        if fileName:
            print("文件路径:", fileName)

def main():
    app = QApplication(sys.argv)

    fileUploader = FileUploader()
    fileUploader.show()

    sys.exit(app.exec_())

if __name__ == '__main__':
    main()
